/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package	dao;

import Hibernate.HibernateUtil;
import pojo.Dictionary;
import pojo.Website;

import java.util.List;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Vinh Quang
 */
public class DictionaryDAO extends AbstractDAO {

	@Override
	protected Class getPOJOClass() {
		// TODO Auto-generated method stub
		return Dictionary.class;
	}
    public List<Dictionary> getDictionary(){
        List<Dictionary> list = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try{
            String hql = "Select dict from Dictionary dict";
            Query query = session.createQuery(hql);
            list = query.list();
        }
        catch(HibernateException ex){
            
        }
        finally{
            session.close();
            
        }
        return list;
    }
    public void UpdateOrInsert(Dictionary dictionary){
    	Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = null;
		try {
			transaction = session.beginTransaction();
			session.saveOrUpdate(dictionary);
			transaction.commit();
			
		} catch (HibernateException ex) {
			// Log the exception
			transaction.rollback();
		}
		finally {
			session.close();
		}
    }
}
